package Ants;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import Ants.Agent.Agent;
import Ants.Agent.IAgent;
import Ants.Model.Status;

public class Main {
 
	private static List<String> DATA = new ArrayList<String>();
	private static Status STATUS = Status.GetIstance();
	private static IAgent AGENT = new Agent(STATUS);
	
	public static void main(String[] args){

		StringBuilder line = new StringBuilder();
		try {
	        int c;
	        while ((c = System.in.read()) >= 0) {
	            if (c == '\r' || c == '\n') {
	                processInput(line.toString().toLowerCase());
	                line.setLength(0);
	            } else {
	                line = line.append((char)c);
	            }
	        }
		}
		catch (IOException e) {
			e.printStackTrace(System.err);
		}	
	}
	
	private static void processInput(String input){	
		if (input.length() > 0) {
			if (input.equals("ready")){
				STATUS.setup(DATA);
				AGENT.setup(STATUS);
				DATA.clear();
			} 
			else if (input.equals("go")){
				try {
					STATUS.update(DATA);
					AGENT.doTurn(STATUS);
				} catch (Exception e) {
					e.printStackTrace();
				}
				DATA.clear();
			}
			DATA.add(input);
		}		
	}
			
}
